home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 103 / XENIATGM103.iso / Shareware / GoLive 5.0 / MM9.Cab / F1477_ado.info5.asp.9B3B646D_CB56_4EAE_BAB7_3E7E8E41A649 < prev    next >
Text File  |  2000-08-17  |  9KB  |  322 lines

  1. <!-- #INCLUDE FILE="../include/utils.runtime5.asp" -->
  2. <!-- #INCLUDE FILE="../include/ado.runtime5.asp" -->
  3.  
  4. <script runat="server" language="VBScript">
  5.  
  6. ' *****************************************************************************
  7. '
  8. ' info/ado.info5.asp
  9. '
  10. ' Dynamic Link design time support for Microsoft ADO.
  11. '
  12. '
  13. ' COPYRIGHT (c) 1999-2000 Adobe Systems Incorporated. All rights reserved.
  14.  
  15. ' -----------------------------------------------------------------------------
  16. ' Return an XML document containing information about the databases
  17. ' in ../databases.    Valid requests are:
  18. '
  19. '        ado.info5.asp            return the available databases
  20. '            ex) http://localhost/golive/config/info/ado.info5.asp
  21. '        ado.info5.asp?db=<name>    return schema information about a given database
  22. '            ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine
  23.  
  24. RejectUnauthorizedCallers
  25. Response.ContentType = "text/xml"
  26. if False = RuntimeDebug then
  27.     on error resume next
  28. end if
  29.  
  30. if IsEmpty(Request("db")) then
  31.     WriteDatabases
  32. else
  33.     WriteDatabaseSchema Request("db")
  34. end if
  35.  
  36. if Err then
  37.     WriteError
  38. end if
  39.  
  40. ' -----------------------------------------------------------------------------
  41. ' Write out the list of available databases.  XML format:
  42. '
  43. '        <DATABASES>
  44. '            [<DATABASE>...]*
  45.  
  46. function WriteDatabases
  47.  
  48.     dim fileSystem
  49.     dim folder
  50.     dim file
  51.     dim fileName
  52.     dim prevFileName
  53.  
  54.     set fileSystem = CreateObject("Scripting.FileSystemObject")
  55.     set folder = fileSystem.GetFolder(GetDatabasePath())
  56.  
  57.     Response.Write "<DATABASES>" & vbNewLine
  58.     for each file in folder.files
  59.         select case ucase(fileSystem.GetExtensionName(file))
  60.             case "UDL", "DSN", "MDB", "XDB"
  61.                 fileName = fileSystem.GetBaseName(file)
  62.                 if fileName <> prevFileName then
  63.                     Response.Write "    <DATABASE>" & fileName & "</DATABASE>" & vbNewLine
  64.                     prevFileName = fileName
  65.                 end if
  66.         end select
  67.     next
  68.     Response.Write "</DATABASES>" & vbNewLine
  69.  
  70. end function
  71.  
  72. ' -----------------------------------------------------------------------------
  73. ' Write out the schema for a given database.  XML format is either:
  74. '        1. no types or sql parameters
  75. '        ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine
  76. '        <DATATYPES>
  77. '            [<DATATYPE>
  78. '               <TYPE_NAME>...
  79. '               <DATA_TYPE>...
  80. '               <IS_LONG>...
  81. '               <SEARCHABLE>...
  82. '               <LITERAL_PREFIX>...
  83. '               <LITERAL_SUFFIX>...]*
  84. '
  85. '        2. types parameter is * or comma-delimited list of table types to return
  86. '        ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine&types=*
  87. '        ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine&types=table,view
  88. '        <TABLES>
  89. '            [<TABLE>...]*
  90. '
  91. '        3. sql parameter gives a query but there is no records parameter
  92. '        ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine&sql=select%20*%20from%20Projects
  93. '        <COLUMNS>
  94. '            [<COLUMN>
  95. '                <COLUMN_NAME>...
  96. '                <DATA_TYPE>... 
  97. '                <ATTRIBUTES>...]*
  98. '        4. records parameter is present (actual data, not schema information)
  99. '        ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine&sql=select%20*%20from%20Projects&records=0
  100. '        <ROWSET>
  101. '            [<ROW>
  102. '                [<fieldname>fieldvalue</fieldname>]*]*
  103.  
  104. '        5. keys parameter is primary key field
  105. '        ex) http://localhost/golive/config/info/ado.info5.asp?db=Magazine&keys=Projects
  106. '        <KEYS>
  107. '            [<PRIMAY_KEY>....
  108.  
  109. function WriteDatabaseSchema(db)
  110.  
  111.     dim connection
  112.  
  113.     set connection = CreateObject("ADODB.Connection")
  114.     connection.Open ConnectString(db)
  115.  
  116.     if IsEmpty(Request("sql")) then
  117.         DoOpenSchema connection 
  118.     else
  119.         AnalyzeRecordset connection.Execute(Request("sql"))
  120.     end if
  121.  
  122. end function
  123.  
  124. ' -----------------------------------------------------------------------------
  125. ' Handles schema requests that need OpenSchema
  126.  
  127. function DoOpenSchema(connection)
  128.  
  129.     if IsEmpty(Request("keys")) then
  130.         if IsEmpty(Request("types")) then
  131.             OpenTypesSchema connection
  132.         else
  133.             OpenTablesSchema connection, Request("types")
  134.         end if
  135.     else
  136.         OpenKeysSchema connection, Request("keys")
  137.     end if
  138.  
  139. end function
  140.  
  141. ' -----------------------------------------------------------------------------
  142. ' Get provider types
  143.  
  144. function OpenTypesSchema(connection)
  145.  
  146.     dim datatypes, typefields, field
  147.  
  148.     typefields = Array("TYPE_NAME", "DATA_TYPE", "IS_LONG", "SEARCHABLE", "LITERAL_PREFIX", "LITERAL_SUFFIX")
  149.  
  150.     set datatypes = connection.OpenSchema(adSchemaProviderTypes)
  151.  
  152.     Response.Write "<DATATYPES>" & vbNewLine
  153.     while not datatypes.EOF
  154.         dim typefield
  155.  
  156.         Response.Write "    <DATATYPE>" & vbNewLine
  157.  
  158.         for each typefield in typefields
  159.             set field = datatypes(typefield)
  160.             value = field.Value
  161.             if value = "null" then value = ""
  162.             Response.Write "        <" & field.Name & ">" & value & "</" & field.Name & ">" & vbNewLine
  163.         next
  164.  
  165.         Response.Write "    </DATATYPE>" & vbNewLine
  166.  
  167.         datatypes.MoveNext
  168.     wend
  169.     Response.Write "</DATATYPES>" & vbNewLine
  170.  
  171. end function
  172.  
  173. ' -----------------------------------------------------------------------------
  174. ' Get primary key fields
  175.  
  176. function OpenKeysSchema(connection, keys)
  177.     dim catalog, index
  178.     tableName = keys
  179.  
  180.     set catalog = CreateObject("ADOX.Catalog")
  181.     set catalog.ActiveConnection = connection
  182.  
  183.     Response.Write "<KEYS>" & vbNewLine
  184.     for each index in catalog.Tables( tableName ).Indexes
  185.         if False = testIndexColumns( index ) then
  186.             exit for
  187.         end if
  188.         if index.PrimaryKey = True then
  189.             for i = 0 to index.Columns.Count - 1
  190.                 Response.Write "    <PRIMARY_KEY>" & index.Columns(i).Name & "</PRIMARY_KEY>" & vbNewLine
  191.             next
  192.         end if
  193.     next
  194.     Response.Write "</KEYS>" & vbNewLine
  195.  
  196. end function
  197.  
  198. ' -----------------------------------------------------------------------------
  199. ' Get table names
  200.  
  201. function OpenTablesSchema(connection, typesString)
  202.  
  203.     dim tables
  204.     
  205.     if typesString = "*" then
  206.         set tables = connection.OpenSchema(adSchemaTables)
  207.         Response.Write "<TABLES>" & vbNewLine
  208.         while not tables.EOF
  209.             Response.Write "    <TABLE>" & tables("TABLE_NAME") & "</TABLE>" & vbNewLine
  210.             tables.MoveNext
  211.         wend
  212.         Response.Write "</TABLES>" & vbNewLine
  213.     else
  214.         dim types, weparse, i, j
  215.         weparse = False
  216.  
  217.         types = Split(typesString, ",")
  218.  
  219.         Response.Write "<TABLES>" & vbNewLine
  220.         on error resume next
  221.  
  222.         for i = LBound(types) to UBound(types)
  223.             set tables = connection.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, types(i)))
  224.             if Err then
  225.                 we parse = True
  226.                 exit for
  227.             end if
  228.  
  229.             while not tables.EOF
  230.                 Response.Write "    <TABLE>" & tables("TABLE_NAME") & "</TABLE>" & vbNewLine
  231.                 tables.MoveNext
  232.             wend
  233.         next
  234.  
  235.         if weparse then
  236.             set tables = connection.OpenSchema(adSchemaTables)
  237.             while not tables.EOF
  238.                 for j = i to UBound(types)
  239.                     if types(j) = tables("TABLE_TYPE") then
  240.                         Response.Write "    <TABLE>" & tables("TABLE_NAME") & "</TABLE>" & vbNewLine
  241.                     end if
  242.                 next
  243.  
  244.                 tables.MoveNext
  245.             wend
  246.         end if
  247.  
  248.         Response.Write "</TABLES>" & vbNewLine
  249.     end if
  250.  
  251. end function
  252.  
  253. ' -----------------------------------------------------------------------------
  254. ' Handles schema requests from recordsets
  255.  
  256. function AnalyzeRecordset(rs)
  257.  
  258.     dim fields, field, recordsString
  259.     set fields = rs.Fields
  260.     
  261.     recordsString = Request("records")
  262.     if IsEmpty(recordsString) then
  263.         dim i
  264.  
  265.         Response.Write "<COLUMNS>" & vbNewLine
  266.  
  267.         for i = 0 to fields.Count - 1
  268.             set field = fields(i)
  269.             Response.Write "    <COLUMN>" & vbNewLine
  270.             Response.Write "        <COLUMN_NAME>" & field.Name & "</COLUMN_NAME>" & vbNewLine
  271.             Response.Write "        <DATA_TYPE>" & field.Type & "</DATA_TYPE>" & vbNewLine
  272.             Response.Write "        <ATTRIBUTES>" & field.Attributes & "</ATTRIBUTES>" & vbNewLine
  273.             Response.Write "    </COLUMN>" & vbNewLine
  274.         next
  275.  
  276.         Response.Write "</COLUMNS>" & vbNewLine
  277.     else
  278.         dim records
  279.         records = split(recordsString, ",")
  280.         rs.Move records(0)
  281.         
  282.         Response.Write "<ROWSET>" & vbNewLine
  283.         
  284.         do
  285.             Response.Write "    <ROW>" & vbNewLine
  286.             for i = 0 to fields.Count - 1
  287.                 set field = fields(i)
  288.                 Response.Write "        <" & field.Name & ">" & field.Value & "</" & field.Name & ">" & vbNewLine
  289.             next
  290.             Response.Write "    </ROW>" & vbNewLine
  291.             
  292.             if CLng(records(0)) >= CLng(records(ubound(records))) then exit do
  293.             records(0) = records(0) + 1
  294.             rs.MoveNext
  295.         loop while not (rs.EOF or Err)
  296.         
  297.         Response.Write "</ROWSET>" & vbNewLine
  298.     end if
  299.  
  300. end function
  301.  
  302. ' -----------------------------------------------------------------------------
  303. ' Write out an error message as XML.
  304.  
  305. function WriteError
  306.  
  307.     dim qt
  308.  
  309.     qt = chr(34)
  310.     Response.Write "<ERROR" 
  311.     Response.Write " Number="        & qt    & Err.Number            & qt
  312.     Response.Write " Source="        & qt    & Err.Source            & qt
  313.     Response.Write " Description="    & qt    & Err.Description        & qt
  314.     Response.Write " HelpFile="        & qt    & Err.HelpFile            & qt
  315.     Response.Write " HelpContext="    & qt    & Err.HelpContext        & qt
  316.     Response.Write "/>" & vbNewLine
  317.     
  318. end function
  319.  
  320. </script>
  321.